package cn.neusoft.controller;

import cn.neusoft.pojo.CartItem;
import cn.neusoft.query.CartItemQuery;
import cn.neusoft.service.ICartItemService;
import cn.neusoft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cart")
public class CartItemController {

    @Autowired
    ICartItemService cartItemService;

    @PostMapping      //  请求方式 + 请求路径   post  /cartItem
    public ResultBean add(@RequestBody CartItem cartItem){
        System.out.println("----CartItemController-----add--------");
        System.out.println(cartItem);
        return cartItemService.add(cartItem);
    }

    @PutMapping    //   put   /cartItem
    public ResultBean update(@RequestBody CartItem cartItem){
        System.out.println("-------CartItemController--------update-------------");
        System.out.println(cartItem);
        return cartItemService.update(cartItem);
    }

    //  delete   /cartItem/1003
    @DeleteMapping("/{id}")   // http://localhost:8080/cartItem/1003
    public ResultBean del(@PathVariable("id") Integer id){
        System.out.println("-------CartItemController--------del-------------");
        System.out.println(id);
        return cartItemService.delete(id);
    }

    //  get   /cartItem/1004
    @GetMapping("/{id}")   // http://localhost:8080/cartItem/1003
    public ResultBean getById(@PathVariable("id") Integer id){
        System.out.println("-------CartItemController--------getById-------------");
        System.out.println(id);
        return cartItemService.getById(id);
    }

    @GetMapping("/all")    //  get  /cartItem/all
    public ResultBean getAll(){
        System.out.println("-------CartItemController-----getAll--------");
        return cartItemService.getAll();
    }

    @PostMapping("/page")   // post  /cartItem/page
    public ResultBean getByPage(@RequestBody CartItemQuery cartItemQuery){
        System.out.println("-------CartItemController--------getByPage-------------");
        System.out.println(cartItemQuery);
        return cartItemService.getByPage(cartItemQuery);
    }

}
